capture	log close
log using MAR05-QuantModels-UNODC,  replace text

//  program:    Stata 
//  task:       Quantile Regression for Panel Data
//  project:    Markets  

version
clear all
macro drop _all
set linesize 80
set more off
local tag " 06-25-24| Cleaned 06-25-24"
local file "MAR05-QuantModels-UNODC"
local note "|`tag' | `file'"
local opt "noparen sideway excel noaster  bdec(2)  sdec(2)  pdec(3)   adec(2) e(r2) stats(coef se pval)"
local dv "lrhom_un"
local iv "fraser"
local iv2 "infantmort" 
local cont "edu unemp  popdense perurban  sexratio"

//	#0
//	Loading data 
use MAR04-ModModels-UNODC.dta, clear 

//	#1
//	Fraser quantile regression for panel models 
foreach quant in  25 50 75  {
	qregpd `dv' `iv' `iv2' `cont' , quantile(0.`quant') id(CID) fix(year)
	estimates store q1_`quant'
	}
estimates table q1_25 q1_50 q1_75, b(%7.2f) se(%7.2f) p(%4.3f)

//	#2
//	Heritage quantile regression for panel models 
foreach quant in  25 50 75  {
	qregpd `dv' heritage `iv2' `cont' , quantile(0.`quant') id(CID) fix(year)
	estimates store q2_`quant'
	}
estimates table q2_25 q2_50 q2_75, b(%7.2f) se(%7.2f) p(%4.3f)


//	#3
//	ROL quantile regression for panel models 
foreach quant in  25 50 75  {
	qregpd `dv' rol `iv2' `cont' , quantile(0.`quant') id(CID) fix(year)
	estimates store q3_`quant'
	}
estimates table q3_25 q3_50 q3_75, b(%7.2f) se(%7.2f) p(%4.3f)

//	#4
//	Exporting results
esttab q1_25 q1_50 q1_75   q2_25 q2_50 q2_75   q3_25 q3_50 q3_75 using "`file'", replace cells(b se p) 

//	#5
//	save and close 
save `file'.dta, replace 
log close 
//